import React, { Component } from "react";
import { connect } from "react-redux";
import { openWebView } from "@tools/native/navigate";
import MainLayout from "../../../component/mainLayout/mainLayout";
import Banner from "@/views/viewCommon/Banner";
import "./TransferXHBSuccess.scss";
import yhTools from "../../../tools/yh";
import { InterfaceG } from "@config/Config";
import { ThemeDefault, ThemeLife } from "../../../tools/theme";

class TransferXHBSuccess extends Component {
	constructor(props) {
		super(props);
		this.state = {
			comeType: this.props.match.params.comeType,
			initData: JSON.parse(this.props.match.params.data) || {},
			bannerList: [] // 轮播图
		};
	}

	componentDidMount() {
		let comeType = this.props.match.params.comeType;
		if (comeType === "into") {
			//转入
			this.getBannerListByPageType(
				"lcBuySuccessPage",
				"lcBuySuccess_bottemBanner"
			);
		} else {
			//转出
			this.getBannerListByPageType(
				"lcSallerSuccessPage",
				"lcSallerSuccess_bottemBanner"
			);
		}
	}
	getBannerListByPageType = (type, name) => {
		const params = {
			url: InterfaceG.getBannerListByPageType,
			params: {
				pageType: type
			},
			_alertShow: false
		};
		yhTools.request(params).then(res => {
			if (res.code === "0") {
				if (res.data && res.data.length > 0) {
					res.data.forEach(item => {
						if (item.bannerType == name) {
							this.setState({
								bannerList: item.indexServerDtos ? item.indexServerDtos : []
							});
						}
					});
				}
			}
		});
	};
	render() {
		const { comeType, initData, bannerList } = this.state;
		const headerParams = {
			header: {
				title: comeType === "into" ? "转入小辉宝" : "转出小辉宝",
				goBackPath: "/walletHome"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles,
			loadStatus: "1" // （ '0'：数据加载中，'1'：加载完成，'2'：加载失败）
		};
		return (
			<MainLayout pageParams={headerParams}>
				<div className="transfer-XHB-success-page">
					<div className="top-content">
						<img
							className="top-img"
							src={require("../../../images/icon/ok.png")}
						/>
						<div className="tips">
							{comeType === "into" ? "转入" : "转出"}成功
						</div>
						<div className="line-1">
							<div className="item">
								<div className="item-top">
									{comeType === "into" ? "转入" : "转出"}金额
								</div>
								<div className="item-bottom">¥{initData.tradeAmount}</div>
							</div>
							<div className="item">
								<div className="item-top">
									{comeType !== "into" && "剩余"}持有总金额
								</div>
								<div className="item-bottom">¥{initData.totalAmount}</div>
							</div>
						</div>
					</div>
					{comeType === "into" && (
						<div className="line-2">
							<div className="t-type">
								<div className="t-left">起息日</div>
								<div className="t-right">{initData.incomeBeginDate}</div>
							</div>
							<div className="t-type">
								<div className="t-left">下一个派息日</div>
								<div className="t-right">{initData.nextDrawProfitDate}</div>
							</div>
							<div className="t-type">
								<div className="t-left">可转出日</div>
								<div className="t-right">{initData.canRedeemDate}</div>
							</div>
						</div>
					)}
					{false /** 1.9版本原型调整，这里不再显示*/ && (
						<div className="line-3">
							<div className="item t-b" onClick={this.gotoNext.bind(this, 1)}>
								查看存单
							</div>
							<div className="item t-w" onClick={this.gotoNext.bind(this, 2)}>
								继续转入
							</div>
						</div>
					)}

					<div className="line-3">
						<ThemeDefault>
							<div className="item t-ok" onClick={this.gotoNext.bind(this, 3)}>
								完成
							</div>
						</ThemeDefault>
						<ThemeLife>
							<div
								className="item t-ok a-gradient"
								onClick={this.gotoNext.bind(this, 3)}
							>
								完成
							</div>
						</ThemeLife>
					</div>
					<Banner bannerList={bannerList} history={this.props.history} />
				</div>
			</MainLayout>
		);
	}
	gotoNext(i) {
		let url;
		if (i === 1) {
			//查看存单
			url = `/depositDetail`;
		} else if (i === 2) {
			//转入
			url = `/transferXHBInto`;
		} else if (i === 3) {
			url = `/walletHome`;
		}
		yhTools.clearPageCache(); //清除所有cachePage
		this.props.history.push({
			pathname: url
		});
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps() {
	return {};
}

export default connect(mapStateToProps, mapDispatchToProps)(TransferXHBSuccess);
